#列车信息表
class CreateTrains < ActiveRecord::Migration
  def self.up
    create_table :trains do |t|
      t.string    :sn                                                           #动车编号
      t.integer   :train_type                                                   #动车类型  2代表二型车，5代表五型车

      t.integer   :router_number                                                #交路的个数，有几个交路个数，用于和日期差数取余
      t.date      :date ,:default => "2010-08-21"                               #车上存储的信息的更新日期
      t.date      :router_date                                                  #列车交路的设置时间
      t.integer   :last_length  ,:default => 0                                  #上次走行公里
      t.integer   :now_length   ,:default => 0                                  #本次走行公里
      t.integer   :all_length   ,:default => 0                                  #总走行公里
      t.integer   :xx_length    ,:default => 0                                  #镟修后公里
      t.integer   :ts_length    ,:default => 0                                  #探伤后公里
      t.integer   :two_level_fix_length    ,:default => 0                       #二级修后公里
      t.integer   :threex_length           ,:default => 0                       #三级修后公里
      t.integer   :fourx_length            ,:default => 0                       #四级修后公里

      t.string              :train_number                                       #车次组合，仅用作显示当前信息，不存数据！
      t.string              :line                                               #行车路线，仅用作显示当前信息，不存数据！
      t.integer             :length                                             #一次行走公里数，仅用作显示当前信息，不存数据！
      t.integer             :firstRouterId
      t.integer             :secondRouterId
      t.integer             :thirdRouterId

      t.integer   :is_locked     ,:limit => 1 ,:default => 0                    #锁定 1为True 0为False
      t.integer   :lock_version  ,:default => 0                                 #乐观锁
      t.timestamps
    end
    Train.create(:sn => "CRH2-029A",:train_type => 2)
    Train.create(:sn => "CRH2-031A",:train_type => 2)
    Train.create(:sn => "CRH2-032A",:train_type => 2)
    Train.create(:sn => "CRH2-035A",:train_type => 2)
    Train.create(:sn => "CRH2-036A",:train_type => 2)
    Train.create(:sn => "CRH2-040A",:train_type => 2)
    Train.create(:sn => "CRH2-041A",:train_type => 2)
    Train.create(:sn => "CRH5-061A",:train_type => 5)
    Train.create(:sn => "CRH5-062A",:train_type => 5)
    Train.create(:sn => "CRH5-065A",:train_type => 5)
    Train.create(:sn => "CRH5-066A",:train_type => 5)
    Train.create(:sn => "CRH5-067A",:train_type => 5)
    Train.create(:sn => "CRH5-068A",:train_type => 5)
    Train.create(:sn => "CRH5-069A",:train_type => 5)
    Train.create(:sn => "CRH5-070A",:train_type => 5)
    Train.create(:sn => "CRH5-071A",:train_type => 5)
    Train.create(:sn => "CRH5-072A",:train_type => 5)
    Train.create(:sn => "CRH5-073A",:train_type => 5)
    Train.create(:sn => "CRH5-074A",:train_type => 5)
    Train.create(:sn => "CRH5-075A",:train_type => 5)
    Train.create(:sn => "CRH5-076A",:train_type => 5)
  end

  def self.down
    drop_table :trains
  end
end
